# -*- coding : utf_8 -*-
"""
=======================================
Time : 2025/3/24 15:10
Author : 田霄汉
Email : 522989570@qq.com
File : verifycode_util.py
Project : pytest_demo
=======================================
"""
import ddddocr


class VerifyCodeUtil:

    @classmethod
    def get_image_verifycode(cls, image_url):
        """
        获取图片形式验证码
        :param image_url: 验证码图片的url
        :return: 验证码
        """
        try:
            ocr = ddddocr.DdddOcr()
            # 验证码图片url需要用二进制方式打开
            with open(image_url, 'rb') as f:
                img_bytes = f.read()
                verify_code = ocr.classification(img_bytes)
            return verify_code
        except Exception as e:
            print(f'获取验证码报错，错误信息{e}')
